package com.example.springstudy.coucrrentSummary;

import java.util.ArrayList;
import java.util.concurrent.*;

/**
 * @Auther ZhaoJunZhou
 * @Date 2020/5/13
 */
public class FetureTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService pool= new ThreadPoolExecutor(0, Integer.MAX_VALUE,
                20, TimeUnit.SECONDS,
                new SynchronousQueue());
        for (FetureTest f : list()) {
            Future<String> future = pool.submit(new Callable<String>() {
                @Override
                public String call() throws Exception {
                    return f.fff();
                }
            });
            System.out.println(future.get());

        }
    }

    public static ArrayList<FetureTest> list() {
        ArrayList<FetureTest> fetureTests = new ArrayList<>();
        fetureTests.add(new FetureTest());
        fetureTests.add(new FetureTest());
        fetureTests.add(new FetureTest());
        fetureTests.add(new FetureTest());
        fetureTests.add(new FetureTest());
        return fetureTests;
    }

    public String fff() throws InterruptedException {
        Double l = Math.random()*10;
        Thread.sleep((long) (l*1000L));
        return "asdfsd"+l;
    }
}
